package org.csu.mybigpro.controller;

import org.csu.mybigpro.common.CommonResponse;
import org.csu.mybigpro.domain.AttendanceRecord;
import org.csu.mybigpro.service.IAttendanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/api/attendance")
public class AttendanceController {

    @Autowired
    private IAttendanceService attendanceService;

    @PostMapping("/clock-in")
    public CommonResponse<AttendanceRecord> clockIn(@RequestBody Map<String, String> payload) {
        try {
            String context = payload.get("context");
            AttendanceRecord record = attendanceService.clockIn(context);
            return CommonResponse.createForSuccess("打卡成功", record);
        } catch (Exception e) {
            return CommonResponse.createForError(e.getMessage());
        }
    }
}
